'use strict';
/**
 * model
 */
export default class extends think.model.base {
	/**
	 * 登录
	 * @param params
	 * @returns {Promise.<*>}
	 */
	async findUserModel( params ) {
		let findUserData = await this.model( 'users' ).where( params ).find();
		return findUserData;
	}

	/**
	 * 注册
	 * @param params 参数
	 * @returns {Promise.<*>}
	 */
	async registerUserModel( params ) {

		let param = {
			userID: think.md5( Date.now() ),
			userAccount: params.userAccount,
			userPassword: think.md5( params.userPassword ),
			userSex: params.userSex,
			userName: params.userName,
			userPhoto: params.userPhoto,
			userEmail: params.userEmail,
			userMobile: params.userMobile,
			userQQ: params.userQQ,
			userSignature: params.userSignature,
			userRegisterTime: think.datetime( new Date, 'YYYY-MM-DD HH:mm:ss' )
		};
		let findUserData = await this.model( 'users' ).where( { userAccount: params.userAccount } ).find();
		if ( think.isEmpty( findUserData ) ) {
			await  this.model( 'users' ).add( param );
			return true;
		} else {
			return false;
		}

	}

	/**
	 * 查找一条数据
	 * @param id
	 * @returns {Promise.<void>}
	 */
	async findUserModelIDModel( id ) {
		return await this.model( 'users' ).where( { userID: id } ).find();
	}

	/**
	 * 删除user数据
	 * @param id
	 * @returns {Promise.<void>}
	 */
	async deleteUserModel( id ) {
		return await  this.model( 'users' ).delete( { where: { userID: id } } );
	}

	/**
	 * 查找所有用户
	 * @returns {Promise.<*>}
	 */
	async findUserListsModel() {
		return await  this.model( 'users' ).select();
	}

	/**
	 * 添加文章分类
	 * @returns {Promise.<void>}
	 */
	async addArticleTypeModel( params ) {
		return await  this.model( 'artType' ).add( params );
	}

	/**
	 * 查看文章分类
	 * @returns {Promise.<void>}
	 */
	async getArticleTypeModel() {
		return await  this.model( 'artType' ).select();
	}

	/**
	 * 重置密码
	 * @param id
	 * @returns {Promise.<*>}
	 */
	async resetUserPwdModel( id ) {
		return await  this.model( 'users' ).update( { userPassword: think.md5( '123456' ) }, { where: { userID: id } } );
	}
}